<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>TitleUp1</title>
</head>
<link href="./layui/css/layui.css" rel="stylesheet">
<body>
<div style="margin: 0 auto;width:70%;display: block">
    <h1 id="show">正在请求</h1>

    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="zwbt" required  placeholder="请输入内容" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <textarea name="zwnr" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>
</div>
</body>
</html>
<script src="./js/jquery-1.9.1.min.js"></script>
<script src="./layui/layui.js"></script>

<script>
    var cache_data={}
    function GetRequest() {
        var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for(var i = 0; i < strs.length; i ++) {
                theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }
    function getInfo(id) {
        $.ajax({
            type: 'get',
            url: './titleList.php?titleType=id&id='+id,
            success: function (data) {
                var jsonData = JSON.parse(data);
                console.log(jsonData)
                if (jsonData.status) {
                    cache_data=jsonData.msg;
                    $("#show").html("修改："+jsonData.msg["正文标题"])
                    $('[name="zwbt"]').val(jsonData.msg["正文标题"])
                    var zwnr="";
                    if (jsonData.msg["正文内容"]){
                        zwnr=jsonData.msg["正文内容"].replace(/\\r\\n/g,"\n")
                    }
                    $('[name="zwnr"]').val(zwnr)
                    layer.close(loading);
                } else {
                    layer.msg(jsonData.msg)
                    layer.close(loading);
                }
            },
            error: function () {
                layer.msg("请求异常")
                layer.close(loading);

            }
        });
    }

    function submitting() {
        zwnr=$('[name="zwnr"]').val();
         if ($('[name="zwnr"]').val()){
             zwnr=$('[name="zwnr"]').val().replace(/\n|\r\n/g,'\\r\\n')
         }
        console.log(zwnr)
        var params={
            'type':"u1",
            'zwbt':$('[name="zwbt"]').val(),
            'zwnr':zwnr,
            'id':cache_data.id
        }
        $.ajax({
            type:'post',
            url:'./zwToDB.php',
            data:params,
            success:function (data) {
                var jsonData = JSON.parse(data);
                if (jsonData.status){
                    layer.msg(jsonData.msg)
                }else {
                    layer.msg(jsonData.msg)
                }
            },
            error:function () {
                layer.msg("请求异常")

            }
        });

    }


    var Request = new Object();
    Request = GetRequest();


    //$("#title").html(Request['id'])
    if (Request['id']){
        var loading = layer.load();
        getInfo(Request['id'])
    }else {
        layer.msg("请重新进入")
    }


</script>